import axios from 'axios';
import QS from 'qs';
import code from './code.json';
import url from './url.json'

let loadTypes = function(){
    return axios({
        url:url.types,
        method:"post",
    }).then(function({ data }){
        return data;
    })
}

let loadFilmById = function(filmId){
    return axios({
        url:"http://127.0.0.1/filmApi/loadFilmById.php",
        method:"get",
        params:{
            filmId
        }
    }).then(function({ data }){
        return data;
    })
}

let loadFilmList = function(data={}){
    return axios({
        url:"http://127.0.0.1/filmApi/loadFilms.php",
        method:"post",
        data:QS.stringify(data)
    }).then(function({ data }){
        return data;
    })
}

let updateFile = function(fd,callback=function(){}){
    return axios({
        url:"http://127.0.0.1/filmApi/uploadTest.php",
        method:"post",
        data:fd,
        onUploadProgress:callback
    }).then(function({ data }){
        return data;
    })
}

export default {
    loadTypes,
    loadFilmById,
    loadFilmList,
    updateFile,
    code:code
}